package com.easyedu.core.dao;

import com.easyedu.core.entity.po.Course;
import com.easyedu.core.entity.query.CourseQuery;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author lmr
 **/
@Mapper
public interface CourseDao {
    /**
     * 功能描述:根据条件获取课程信息
     *
     * @param courseQuery 1 课程查询数据
     * @return : java.util.List<com.easyedu.api.entity.DO.Course>
     **/
    @Select({"<script>select * from course where " +
            "<if test='openInstituteName!=null'>open_institute_name = #{openInstituteName} AND </if>" +
            "<if test='courseCode!=null'>course_code = #{courseCode} AND </if>" +
            "<if test='courseName!=null'>course_name = #{courseName} AND </if>" +
            "<if test='courseNature!=0'>course_nature = #{courseNature} AND </if>" +
            "<if test='examinationMethod!=0'>examination_method = #{examinationMethod} AND </if>" +
            "<if test='gradeType!=0'>grade_type = #{gradeType} AND </if>" +
            "1 = 1</script>"})
    List<Course> getCourse(CourseQuery courseQuery);

    /**
     * 功能描述:插入课程
     *
     * @param course 1 课程 course表 Persistant Object
     * @return : void
     **/
    @Options(useGeneratedKeys = true, keyProperty = "courseId", keyColumn = "course_id")
    @Insert("insert into course(open_institute_id, open_institute_name, course_code, course_name, course_nature, " +
            "have_in_class_experiment, examination_method, credit, grade_type, note, create_time, update_time) VALUES" +
            " (#{openInstituteId},#{openInstituteName},#{courseCode},#{courseName},#{courseNature}," +
            "#{haveInClassExperiment},#{examinationMethod},#{credit},#{gradeType},#{note},NOW(),NOW())")
    Integer createCourse(Course course);

    /**
     * 功能描述: 获取课程
     *
     * @param courseId 1 课程id
     * @return : com.easyedu.api.entity.DO.Course
     **/
    @Select("select * from course where course_id = #{courseId}")
    Course getCourseById(long courseId);

    /**
     * 功能描述:根据课程代码查找课程
     *
     * @param courseCode 1 课程代码
     * @return : com.easyedu.api.entity.DO.Course
     **/
    @Select("select * from course where course_code = #{courseCode}")
    Course getCourseByCode(String courseCode);
}
